<?php

//PLUGIN type=action
//PLUGIN name=page.add
//PLUGIN desc=Enables you to add pages to your site
//PLUGIN group=native


    $p;

    function create_new_page()
    {
        global $options, $p;
        $theName = (isset($options['name'])) ? $options['name'] : time();
        $p = ($options['prenamed']) ? $options['page'] : $options['page'] . "/" . $theName;
        $mk1 = _CONTENTPATH_ . $p;
        $mk2 = $mk1 . "/!content";
        $index_xml_file_path = __ADMIN_DIR__ . "/templates/template.content.index.xml";
        if (!file_exists($index_xml_file_path))
            return "template.content.index.xml does not exist!";
        if (!mkdir($mk1))
            return "could not create " . $mk1;
        if (!mkdir($mk2))
            return "could not create " . $mk2;
        if (!copy($index_xml_file_path, $mk1 . "/index.xml"))
            return "failed to copy template.content.index.xml from templates dir! system might have been corupted by this.";
        return true;
    }

    if ($msg = create_new_page())
    {
        header("Location:?q=command:cms;view:cms.page.settings;page:" . $p . ";");
        exit("Error in " . __FILE__);
    }
    else
    {
        $smarty->assign('msg', $msg);
    }

?>